Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jan 12, 2026

Important

Add optional metadata argument to score and score_trace methods in langfuse/_client/span.py to allow attaching additional data to scores.

  • Behavior:
    • Add metadata argument to score() and score_trace() methods in langfuse/_client/span.py.
    • metadata is optional and allows attaching additional data to scores.
  • Methods:
    • Update score() and score_trace() to include metadata in all overloads and internal create_score calls.

This description was created by Ellipsis for 44ce8e0. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Overview

Greptile Summary

This PR adds optional metadata parameter support to the score() and score_trace() methods in the LangfuseObservationWrapper class, enabling users to attach additional contextual data to scores.

Changes Made

  • Added metadata: Optional[Any] = None parameter to both overloads and implementations of score() method (lines 280, 294, 307)
  • Added metadata: Optional[Any] = None parameter to both overloads and implementations of score_trace() method (lines 363, 377, 390)
  • Updated docstrings to document the new parameter
  • Modified internal create_score calls to pass the metadata parameter through (lines 349, 432)

Implementation Details

The implementation correctly passes the metadata parameter through to the underlying create_score method in the Langfuse client, which already supports metadata via the ScoreBody API type. The feature is backward compatible since metadata is optional and defaults to None.

Issue Found

Parameter Order Inconsistency: The PR adds metadata after timestamp in the method signatures, but the underlying create_score method in client.py has metadata before timestamp. While this doesn't cause functional issues (all parameters are keyword-only), it creates an API inconsistency that could confuse developers and violates the principle of matching parameter order with the underlying implementation.

Confidence Score: 4/5

  • This PR is safe to merge with minor style improvements recommended
  • The implementation is functionally correct and complete - all overloads are updated, the parameter is properly typed, documented, and passed through to the underlying API which already supports it. The feature is backward compatible and follows existing patterns. The score is 4/5 (not 5/5) due to a parameter ordering inconsistency with the underlying create_score method that should be fixed for API consistency, though this is a non-critical style issue that doesn't affect functionality.
  • No files require special attention - the single style comment addresses parameter ordering across all affected methods

Important Files Changed

File Analysis

Filename Score Overview
langfuse/_client/span.py 4/5 Added optional metadata parameter to score() and score_trace() methods; parameter order inconsistency found

Sequence Diagram

sequenceDiagram
    participant User
    participant Span as LangfuseObservationWrapper
    participant Client as Langfuse Client
    participant API as Score API

    User->>Span: span.score(name, value, metadata={...})
    Note over Span: Validates parameters<br/>Prepares score data
    Span->>Client: create_score(name, value, trace_id, observation_id, metadata)
    Note over Client: Creates ScoreBody<br/>with metadata field
    Client->>API: POST score-create event
    Note over API: Score stored with<br/>attached metadata
    API-->>Client: Success
    Client-->>Span: Score created
    Span-->>User: Returns

    User->>Span: span.score_trace(name, value, metadata={...})
    Note over Span: Validates parameters<br/>Prepares trace score
    Span->>Client: create_score(name, value, trace_id, metadata)
    Note over Client: Creates ScoreBody<br/>with metadata field
    Client->>API: POST score-create event
    Note over API: Trace score stored<br/>with metadata
    API-->>Client: Success
    Client-->>Span: Score created
    Span-->>User: Returns
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@hassiebp hassiebp enabled auto-merge (squash) January 12, 2026 15:25
@hassiebp hassiebp merged commit f4148bc into main Jan 12, 2026
12 checks passed
@hassiebp hassiebp deleted the add-score-metadata-to-span-client branch January 12, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants